package com.cares.event.listener.servicestart;

import java.util.List;
import java.util.TimerTask;

import javax.servlet.ServletContext;

import com.cares.event.constant.EventSystemConstant;
import com.cares.event.dto.EventActivityDto;
import com.cares.event.service.EventExecutionService;

public class JsflowTask extends TimerTask {
	
    private static boolean isRunning = false;   
    private ServletContext context = null;   
 
    public JsflowTask(ServletContext context){  
        this.context = context ;  
    }  
    
   @Override  
   public void run() {  
 
       if (! isRunning){  
    	   System.out.println("开始执行指定任务.") ;  
           isRunning = true ;  
           context.log("开始执行指定任务--查询待执行的任务") ;  
           //添加自定义的详细任务
           EventExecutionService eventFlowService = (EventExecutionService) cn.sh.cares.core.utils.spring.ApplicationContextHolder.getBean("eventExecutionService");
           List<EventActivityDto> results = eventFlowService.queryEventExecutionDtos();
           EventSystemConstant.eventActivityDtos = results;
           System.out.println("jsflowExecutionDtos"+ results.size()) ;  
           
           isRunning = false;   
           context.log("指定任务执行结束--查询待执行的任务");   
           System.out.println("指定任务执行结束--查询待执行的任务") ;  
       }else{  
           context.log("上一次任务执行还未结束");   
 
       }  
   }  

}

